package com.aidex.system.controller;

import java.util.List;
import com.aidex.common.annotation.Log;
import com.aidex.common.core.domain.R;
import com.github.pagehelper.PageInfo;
import com.aidex.common.core.page.PageDomain;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.aidex.common.enums.BusinessType;
import com.aidex.common.utils.poi.ExcelUtil;
import javax.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import com.aidex.common.core.controller.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import com.aidex.system.domain.OptimizationSuggestionRule;
import com.aidex.system.service.OptimizationSuggestionRuleService;

/**
 * 优化建议规则设置Controller
 * @author jmy
 * @email jmyinjg@163.com
 * @date 2021-10-09
 */
@RestController
@RequestMapping("/system/optimizationSuggestionRule")
public class OptimizationSuggestionRuleController extends BaseController
{
    @Autowired
    private OptimizationSuggestionRuleService optimizationSuggestionRuleService;

    /**
     * 查询优化建议规则设置列表
     */
    @PreAuthorize("@ss.hasPermi('system:optimizationSuggestionRule:list')")
    @GetMapping("/list")
    public R<PageInfo> list(OptimizationSuggestionRule optimizationSuggestionRule, HttpServletRequest request, HttpServletResponse response)
    {
        optimizationSuggestionRule.setPage(new PageDomain(request, response));
        return R.data(optimizationSuggestionRuleService.findPage(optimizationSuggestionRule));
    }

    /**
     * 获取优化建议规则设置详细信息
     */
    @GetMapping
    public R<OptimizationSuggestionRule> detail()
    {
        return R.data(optimizationSuggestionRuleService.getRule());
    }

    /**
     * 新增优化建议规则设置
     */
    @PreAuthorize("@ss.hasPermi('system:optimizationSuggestionRule:add')")
    @Log(title = "优化建议规则设置", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody @Validated  OptimizationSuggestionRule optimizationSuggestionRule)
    {
        return R.status(optimizationSuggestionRuleService.save(optimizationSuggestionRule));
    }

    /**
     * 修改优化建议规则设置
     */
    @PreAuthorize("@ss.hasPermi('system:optimizationSuggestionRule:edit')")
    @Log(title = "优化建议规则设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated OptimizationSuggestionRule optimizationSuggestionRule)
    {
        return R.status(optimizationSuggestionRuleService.save(optimizationSuggestionRule));
    }


    /**
     * 删除优化建议规则设置
     */
    @PreAuthorize("@ss.hasPermi('system:optimizationSuggestionRule:remove')")
    @Log(title = "优化建议规则设置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids)
    {
        return R.status(optimizationSuggestionRuleService.deleteOptimizationSuggestionRuleByIds(ids));
    }


    /**
     * 导出优化建议规则设置列表
     */
    @PreAuthorize("@ss.hasPermi('system:optimizationSuggestionRule:export')")
    @Log(title = "优化建议规则设置", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(OptimizationSuggestionRule optimizationSuggestionRule)
    {
        List<OptimizationSuggestionRule> list = optimizationSuggestionRuleService.findList(optimizationSuggestionRule);
        ExcelUtil<OptimizationSuggestionRule> util = new ExcelUtil<OptimizationSuggestionRule>(OptimizationSuggestionRule.class);
        return util.exportExcel(list, "optimizationSuggestionRule");
    }

}
